package org.csu.jpetstore.service;

import org.csu.jpetstore.domain.Account;
import org.csu.jpetstore.persistence.AccountDAO;
import org.csu.jpetstore.persistence.impl.AccountDAOImpl;

public class AccountService {

    private AccountDAO accountDAO;
    private String msg;

    public AccountService() {
        accountDAO = new AccountDAOImpl();
    }

    public Account login(String username, String password) {
        return accountDAO.getUserByUsernameAndPassword(username, password);
    }

    public boolean usernameExist(String username) {
        return accountDAO.getUserByUsername(username);
    }

    public int register(Account account) {
        if(usernameExist(account.getUsername())) {
            msg = "用户名已存在！";
            return 0;
        }
        else {
            return accountDAO.addUser(account);
        }
    }

    public int updateAccount(Account account) {
        return accountDAO.updateUser(account);
    }

    public int updatePwd(Account account) {
        return  accountDAO.updatePwd(account);
    }

    public String getMsg() {
        return msg;
    }

}
